<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="theme-color" content="#33474d">
	<title>LAMP安装php | 失落的乐章</title>
	<link rel="stylesheet" href="/css/style.css" />
	
      <link rel="alternate" href="/atom.xml" title="失落的乐章" type="application/atom+xml">
    
</head>

<body>

	<header class="header">
		<nav class="header__nav">
			
				<a href="/archives" class="header__link">Archive</a>
			
				<a href="/tags" class="header__link">Tags</a>
			
				<a href="/atom.xml" class="header__link">RSS</a>
			
		</nav>
		<h1 class="header__title"><a href="/">失落的乐章</a></h1>
		<h2 class="header__subtitle">技术面前，永远都是学生。</h2>
	</header>

	<main>
		<article>
	
		<h1>LAMP安装php</h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/LAMP/">LAMP</a> <a class="article__tag-link" href="/tags/Php/">Php</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;为什么把 php 放到最后来安装，是有原因的，因为在编译 php 的时候，有指定 mysql 以及 apache 的路径，如果不先安装好 mysql 和 apache 就没有办法安装 php 。而 apache 和 mysql 的安装顺序就无所谓了。<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<a href="http://www.php.net/downloads.php" target="_blank" rel="external">php官方下载地址</a></p>
<h2 id="下载-php-："><a href="#下载-php-：" class="headerlink" title="下载 php ："></a>下载 php ：</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[rot@localhost httpd-2.2.16]<span class="comment"># cd /usr/local/src</span></div><div class="line">[root@localhost src]<span class="comment"># wget http://am1.php.net/distributions/php-5.3.27.tar.gz</span></div></pre></td></tr></table></figure>
<h2 id="解压源码包："><a href="#解压源码包：" class="headerlink" title="解压源码包："></a>解压源码包：</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@localhost src]<span class="comment"># tar zxf php-5.3.27.tar.gz</span></div></pre></td></tr></table></figure>
<h2 id="依赖包安装"><a href="#依赖包安装" class="headerlink" title="依赖包安装"></a>依赖包安装</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">yum install -y bzip2-devel curl-devel db4-devel libjpeg-devel libpng-devel libXpm-devel gmp-devel libc-client-devel openldap-devel unixODBC-devel postgresql-devel sqlite-devel aspell-devel net-snmp-devel libxslt-devel libxml2-devel pcre-devel mysql-devel unixODBC-devel postgresql-devel pspell-devel net-snmp-devel</div></pre></td></tr></table></figure>
<h2 id="配置编译参数："><a href="#配置编译参数：" class="headerlink" title="配置编译参数："></a>配置编译参数：</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div></pre></td><td class="code"><pre><div class="line">root@localhost src]<span class="comment"># cd php-5.3.27</span></div><div class="line">[root@localhost php-5.3.27]<span class="comment"># ./configure \</span></div><div class="line">--prefix=/usr/<span class="built_in">local</span>/php \</div><div class="line">--with-apxs2=/usr/<span class="built_in">local</span>/apache2/bin/apxs \</div><div class="line">--with-config-file-path=/usr/<span class="built_in">local</span>/php/etc \</div><div class="line">--with-mysql=/usr/<span class="built_in">local</span>/mysql \</div><div class="line">--with-libxml-dir \</div><div class="line">--with-gd \</div><div class="line">--with-jpeg-dir \</div><div class="line">--with-png-dir \</div><div class="line">--with-freetype-dir \</div><div class="line">--with-iconv-dir \</div><div class="line">--with-zlib-dir \</div><div class="line">--with-bz2 \</div><div class="line">--with-openssl \</div><div class="line">--with-mcrypt \</div><div class="line">--<span class="built_in">enable</span>-soap \</div><div class="line">--<span class="built_in">enable</span>-gd-native-ttf \</div><div class="line">--<span class="built_in">enable</span>-mbstring \</div><div class="line">--<span class="built_in">enable</span>-sockets \</div><div class="line">--<span class="built_in">enable</span>-exif \</div><div class="line">--<span class="built_in">disable</span>-ipv6</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在这一步，遇到如下错误:</p>
<h3 id="错误1："><a href="#错误1：" class="headerlink" title="错误1："></a>错误1：</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">configure: error: xml2-config not found. Please check your libxml2 installation.</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;解决办法：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">yum install -y libxml2-devel</div></pre></td></tr></table></figure>
<h3 id="错误2："><a href="#错误2：" class="headerlink" title="错误2："></a>错误2：</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">configure: error: Cannot find OpenSSL<span class="string">'s &lt;evp.h&gt;</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;解决办法：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">yum install -y openssl openssl-devel</div></pre></td></tr></table></figure>
<h3 id="错误3："><a href="#错误3：" class="headerlink" title="错误3："></a>错误3：</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">checking <span class="keyword">for</span> BZip2 <span class="keyword">in</span> default path... not found</div><div class="line">configure: error: Please reinstall the BZip2 distribution</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;解决办法：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">yum install -y bzip2 bzip2-devel</div></pre></td></tr></table></figure>
<h3 id="错误4："><a href="#错误4：" class="headerlink" title="错误4："></a>错误4：</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">configure: error: png.h not found.</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;解决办法：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">yum install -y libpng libpng-devel</div></pre></td></tr></table></figure>
<h3 id="错误5："><a href="#错误5：" class="headerlink" title="错误5："></a>错误5：</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">configure: error: freetype.h not found.</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;解决办法：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">yum install -y freetype freetype-devel</div></pre></td></tr></table></figure>
<h3 id="错误6："><a href="#错误6：" class="headerlink" title="错误6："></a>错误6：</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">configure: error: mcrypt.h not found. Please reinstall libmcrypt.</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;解决办法：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">yum install -y epel-release</div><div class="line">yum install -y libmcrypt-devel</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;rpm安装 epel</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">rpm -ivh <span class="string">"http://www.aminglinux.com/bbs/data/attachment/forum/month_1211/epel-release-6-7.noarch.rpm"</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;因为centos 默认的 yum 源没有 libmcrypt-devel 这个包，只能借助 epel 的 yum 源。</p>
<h3 id="错误7："><a href="#错误7：" class="headerlink" title="错误7："></a>错误7：</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">configure: error: jpeglib.h not found.</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;解决办法：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">yum -y install libjpeg-devel</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;编译：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@localhost php-5.3.27]<span class="comment"># make</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;安装：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@localhost php-5.3.27]<span class="comment"># make install</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;安装完成后，还不能使用，还需要进一步配置一下。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;拷贝 php 配置文件：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@localhost php-5.3.27]<span class="comment"># cp php.ini-production /usr/local/php/etc/php.ini</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;修改 apache 配置文件</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@localhost ~]<span class="comment"># vim /usr/local/apache2/conf/httpd.conf</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;找到：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">&lt;Directory /&gt;</div><div class="line"> Options FollowSymLinks</div><div class="line"> AllowOverride None</div><div class="line"> Order deny,allow</div><div class="line"> Deny from all</div><div class="line">&lt;/Directory&gt;</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;改为：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">&lt;Directory /&gt;</div><div class="line"> Options FollowSymLinks</div><div class="line"> AllowOverride None</div><div class="line"> Order deny,allow</div><div class="line"> Allow from all</div><div class="line">&lt;/Directory&gt;</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;说明：如果不修改这个地方，访问网站会禁止访问，显示403。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;然后找到：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">AddType application/x-gzip .gz .tgz</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在该行下添加：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">AddType application/x-httpd-php .php</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;找到：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">&lt;IfModule dir_module&gt;</div><div class="line"> DirectoryIndex index.html</div><div class="line">&lt;/IfModule&gt;</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;将该行改为：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">&lt;IfModule dir_module&gt;</div><div class="line"> DirectoryIndex index.html index.htm index.php</div><div class="line">&lt;/IfModule&gt;</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;说明：增加针对 php 的索引，如果一个站点默认页为 index.php ，那么就得加上这个index.php 的支持。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;再找到：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="comment">#ServerName www.example.com:80</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;修改为：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">ServerName www.example.com:80</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;如果不去掉 # ，则启动 apache 时，会有警告信息 <code>“httpd: Could not reliably determine the server&#39;s fully qualified domain name, using localhost.localfomain for SververName”</code>，看起来像是错误，其实没有影响。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;查看配置文件是否有问题：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@localhost ~]<span class="comment"># /usr/local/apache2/bin/apachectl -t</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;如果显示 Syntax OK ，说明配置没有问题。然后启动服务：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@localhost ~]<span class="comment"># /usr/local/apache2/bin/apachectl start</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;检查 apache 是否正常启动的命令是：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div></pre></td><td class="code"><pre><div class="line">[root@lamp ~]<span class="comment"># ps aux |grep httpd</span></div><div class="line">root 1434 0.0 0.2 32576 10184 ? Ss 14:18 0:00 /usr/<span class="built_in">local</span>/apache2/bin/httpd -k start</div><div class="line">daemon 1435 0.0 0.2 32708 9084 ? S 14:18 0:00 /usr/<span class="built_in">local</span>/apache2/bin/httpd -k start</div><div class="line">daemon 1436 0.0 0.2 32708 10012 ? S 14:18 0:00 /usr/<span class="built_in">local</span>/apache2/bin/httpd -k start</div><div class="line">daemon 1437 0.0 0.2 32708 9084 ? S 14:18 0:00 /usr/<span class="built_in">local</span>/apache2/bin/httpd -k start</div><div class="line">daemon 1438 0.0 0.2 32708 9084 ? S 14:18 0:00 /usr/<span class="built_in">local</span>/apache2/bin/httpd -k start</div><div class="line">daemon 1439 0.0 0.2 32708 9084 ? S 14:18 0:00 /usr/<span class="built_in">local</span>/apache2/bin/httpd -k start</div><div class="line">daemon 1440 0.0 0.2 32708 9084 ? S 14:18 0:00 /usr/<span class="built_in">local</span>/apache2/bin/httpd -k start</div><div class="line">root 1459 0.0 0.0 5980 736 pts/0 R+ 15:56 0:00 grep --color httpd</div><div class="line">[root@lamp ~]<span class="comment"># netstat -lnp |grep httpd</span></div><div class="line">tcp   0  0 :::80        :::*       LISTEN 1434/httpd</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;看看有没有进程列表。如果有显示这行，则启动了。 也可以使用curl命令简单测试:</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@localhost ~]<span class="comment"># curl localhost</span></div><div class="line">&lt;html&gt;&lt;body&gt;&lt;h1&gt;It works!&lt;/h1&gt;&lt;/body&gt;&lt;/html&gt;</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;只有这样显示才正确。</p>

	

	
		<span class="different-posts"><a href="/2017/10/12/Php/1. LAMP安装php/" onclick="window.history.go(-1); return false;">⬅️ Go back </a></span>

	

</article>

	</main>

	<footer class="footer">
	<div class="footer-content">
		
	      <div class="footer__element">
	<p>Hi there, <br />welcome to my Blog glad you found it. Have a look around, will you?</p>
</div>

	    
	      <div class="footer__element">
	<h5>Check out</h5>
	<ul class="footer-links">
		<li class="footer-links__link"><a href="/archives">Archive</a></li>
		
		  <li class="footer-links__link"><a href="/atom.xml">RSS</a></li>
	    
		<li class="footer-links__link"><a href="/about">about page</a></li>
		<li class="footer-links__link"><a href="/tags">Tags</a></li>
		<li class="footer-links__link"><a href="/categories">Categories</a></li>
	</ul>
</div>

	    

		<div class="footer-credit">
			<span>© 2017 失落的乐章 | Powered by <a href="https://hexo.io/">Hexo</a> | Theme <a href="https://github.com/HoverBaum/meilidu-hexo">MeiliDu</a></span>
		</div>

	</div>


</footer>



</body>

</html>
